# -*- coding: utf-8 -*-

import time
from report import report_sxw
import pooler
from osv import osv
from tools.translate import _
import random
from datetime import datetime
        
class Parser(report_sxw.rml_parse):
        
    def __init__(self, cr, uid, name, context):
        super(Parser, self).__init__(cr, uid, name, context=context)
        pool = pooler.get_pool(cr.dbname)
        user_obj = pool.get('res.users')
        course_obj = pool.get('aas.course.course')
        course_student_obj = pool.get('aas.course.student')
        
        student_id = context.get('student_id', False)
        self.student = user_obj.browse(cr, uid, student_id, context=context)
        
        self.context = context
        self.year = ''
        self.semester = ''
        self.stt = 0
        self.total_credit = 0
        
        self.register_lines = []
        registers_ids = context.get('registers_ids', [])
        for reg_id in course_student_obj.browse(cr, uid, registers_ids, context=context):
            self.register_lines.append([reg_id.course_id.name,
                                   reg_id.course_id.subject_id.code,
                                   reg_id.course_id.subject_id.name,
                                   reg_id.course_id.total_credit])
            self.total_credit += reg_id.course_id.total_credit
            self.year = reg_id.course_id.list_id.academic_year.name
            self.semester = reg_id.course_id.list_id.academic_semester.name
        
        self.localcontext.update({
            'init': self._init,
            'register_lines': self.register_lines,
            'student': self.student,
            'stt': self._get_stt,
            'year': self.year,
            'semester': self.semester,
            'total_credit': self.total_credit,
            'get_logo': self.get_logo,
        })
    
    def _init(self, student):
#        print student.name
        return True
    
    def get_logo(self):
        user = self.pool.get('res.users').browse(self.cr, self.uid, self.uid)
        logo = False
        if user.company_id:
            company = self.pool.get('res.company').browse(self.cr, self.uid, user.company_id.id)
            logo = company.logo
        return logo
    
    def _get_stt(self):
        self.stt += 1
        return self.stt
    
    def reset_stt(self):
        self.stt = 0
    
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
